home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 …ember: Reference Library / Dev.CD Dec 97 RL.toast / What's New / • What was new 11⁄97 / Tool Chest / Power Mac Debugger / Debugger Extensions / put.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-30  |  3.2 KB  |  189 lines  |  [TEXT/MPS ]

  1. /*    put.c
  2.     This is a set of formatting routines for use by dcmds.
  3.     Copyright © 1988 Apple Computer, Inc.  All rights reserved.
  4.  
  5.     Modification history:
  6.         29Nov88 sad        revised for new dcmd names.
  7.          5Oct88 sad        written from file.c
  8.  */
  9.  
  10. #include <Types.h>
  11. #include "dcmd.h"
  12.  
  13. static Str255 line;
  14. static int linepos = 0;
  15.  
  16.  
  17. static void movebytes ( unsigned char *s, unsigned char *t, register long length ) 
  18. {
  19.     if ((s + length) <= t)
  20.         while (--length >= 0) *t++ = *s++;
  21.     else
  22.         {
  23.         s += length;
  24.         t += length;
  25.         while (--length >= 0) *--t = *--s;
  26.         }
  27. } // movebytes
  28.  
  29.  
  30. #define BlockMove    movebytes
  31.  
  32.  
  33. void PutLine()
  34. {
  35.     BlockMove(line,line+1,linepos);  a toolbox call
  36.     line[0] = linepos;
  37.     dcmdDrawLine(line);
  38.     linepos = 0;
  39. } // PutLine
  40.  
  41.  
  42. void PutChar(char c)
  43. {
  44.     line[linepos++] = c;
  45. } // PutChar
  46.  
  47.  
  48. void PutSpace()
  49. {
  50.     PutChar(' ');
  51. } // PutSpace
  52.  
  53.  
  54. void PutSpacesTo(int pos)
  55. {
  56.     while (linepos < pos) PutSpace();
  57. } // PutSpacesTo
  58.  
  59.  
  60. void PutBytesTruncTo(const char* s, int len, int pos)
  61. {
  62.     if (pos > linepos)
  63.         {
  64.         if (len <= pos - linepos)
  65.             {
  66.             BlockMove(s,line+linepos,len);
  67.             linepos += len;
  68.             while (linepos < pos) PutSpace();
  69.             }
  70.         else
  71.             {
  72.             BlockMove(s,line+linepos,pos-linepos-1);
  73.             linepos = pos - 1;
  74.             PutChar('…');
  75.             }
  76.         line[linepos] = '\0';
  77.         }
  78. } // PutBytesTruncTo
  79.  
  80.  
  81. void PutBytesTo(const char* s, int len, int pos)
  82. {
  83.     BlockMove(s,line+linepos,len);
  84.     linepos += len;
  85.     while (linepos < pos) PutSpace();
  86.     line[linepos] = '\0';
  87. } // PutBytesTo
  88.  
  89.  
  90. void PutCStrTo(const char* s, int pos)
  91. {
  92.     int slen = strlen(s);
  93.     PutBytesTo(s,slen,pos);
  94. } // PutCStrTo
  95.  
  96.  
  97. void PutCStrTruncTo(const char* s, int pos)
  98. {
  99.     int slen = strlen(s);
  100.     PutBytesTruncTo(s,slen,pos);
  101. } // PutCStrTo
  102.  
  103.  
  104. void PutCStr(const char* s)
  105. {
  106.     int slen = strlen(s);
  107.     PutBytesTo(s,slen,0);
  108. } // PutCStr
  109.  
  110.  
  111. void PutPStrTruncTo(const char* s, int pos)
  112. {
  113.     int slen = *(unsigned char *)s;
  114.     PutBytesTruncTo(s+1,slen,pos);
  115. } // PutPStrTo
  116.  
  117.  
  118. void PutPStrTo(const char* s, int pos)
  119. {
  120.     int slen = *(unsigned char *)s;
  121.     PutBytesTo(s+1,slen,pos);
  122. } // PutPStrTo
  123.  
  124.  
  125. void PutPStr(const char* s)
  126. {
  127.     int slen = *(unsigned char *)s;
  128.     PutBytesTo(s+1,slen,0);
  129. } // PutPStr
  130.  
  131.  
  132. void PutUHexZTo(unsigned long i, int ndig, int pos)
  133. {
  134. unsigned long dig = i % 0x10;
  135. unsigned long rest = i / 0x10;
  136.     if (rest != 0) PutUHexZTo(rest,ndig - 1,pos - 1);
  137.     else
  138.         {
  139.         pos -= 1;        // one for this digit
  140.         if (ndig > 0) pos -= ndig - 1;        // the leading zeros
  141.         while (linepos < pos) PutSpace();
  142.         while (--ndig > 0) PutChar('0');
  143.         }
  144.     if (dig < 10) PutChar('0' + dig);
  145.     else PutChar('a' + (dig - 10));
  146. } // PutUHexZTo
  147.  
  148.  
  149. void PutUHexZ(unsigned long i, int nz)
  150. {
  151.     PutUHexZTo(i,nz,0);
  152. } // PutUHexZ
  153.  
  154.  
  155. void PutUHexWord(unsigned long i)
  156. {
  157.     PutUHexZTo((unsigned short)i,4,0);
  158. } // PutUHexZ
  159.  
  160.  
  161. void PutUDecTo(unsigned long i, int pos)
  162. {
  163. unsigned long dig = i % 10;
  164. unsigned long rest = i / 10;
  165.     if (rest != 0) PutUDecTo(rest,pos - 1);
  166.     else
  167.         {
  168.         pos -= 2;    // one for the '#' and one for this digit
  169.         while (linepos < pos) PutSpace();
  170.         PutChar('#');
  171.         }
  172.     PutChar('0' + dig);
  173. } // PutUDecTo
  174.  
  175.  
  176. void PutUDec(unsigned long i)
  177. {
  178.     PutUDecTo(i,0);
  179. } // PutUDec
  180.  
  181.  
  182. void PutOSType(unsigned long typ)
  183. {
  184.     PutChar((typ>>24) & 0xff);
  185.     PutChar((typ>>16) & 0xff);
  186.     PutChar((typ>>8) & 0xff);
  187.     PutChar(typ & 0xff);
  188. } // PutOSType
  189.